/**
 * Copyright (c) Huawei Technologies Co., Ltd. 1987-2021. All rights reserved.
*/

package com.gitee.fufu669.response;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;

/** @author wangfupeng */
@ApiModel("单值返回")
/**
 * TODO
*/
public class SimpleResponse<T> implements Serializable {

    // 赋值
    private static final long serialVersionUID = 1L;
    /**
     * TODO
    */
    protected static final int SUCCESS_STATUS = 200;
    /**
     * TODO
    */
    protected static final String SUCCESS_MESSAGE = "success";

    // TODO
    private T data;
    
    // 注解
    @ApiModelProperty(value = "返回消息, 成功为success", example = "success")
    // TODO
    private String message;
    
    // 注解
    @ApiModelProperty(value = "返回状态, 成功为200", example = "200")
    // TODO
    private int status;
    
    /**
     * TODO
    */
    public T getData() {
        // 返回
        return data;
    }

    /**
     * TODO
    */
    public void setData(T data) {
        // 赋值
        this.data = data;
    }

    /**
     * TODO
    */
    public String getMessage() {
        // 返回
        return message;
    }

    /**
     * TODO
    */
    public void setMessage(String message) {
        // 赋值
        this.message = message;
    }

    /**
     * TODO
    */
    public int getStatus() {
        // 返回
        return status;
    }

    /**
     * TODO
    */
    public void setStatus(int status) {
        // 赋值
        this.status = status;
    }

    /**
     * TODO
    */
    public static <T> SimpleResponse<T> success() {        return success((T) "");    }

    /**
     * TODO
    */
    public static <T> SimpleResponse<T> success(T data) {
        // 返回
        return success(data, SUCCESS_MESSAGE, "");
    }

    /**
     * TODO
    */
    public static <T> SimpleResponse<T> success(T data, String message, String moreInfo) {
        // 返回
        return success(data, message, SUCCESS_STATUS, moreInfo);
    }

    /**
     * TODO
    */
    public static <T> SimpleResponse<T> success(T data, String message, int responseStatus, String moreInfo) {
        // 创建
        SimpleResponse response = new SimpleResponse();
        // TODO
        response.setData(data);
        // TODO
        response.setStatus(responseStatus);
        // TODO
        response.setMessage(message);
        // 返回
        return response;
    }

    /**
     * TODO
    */
    public static <T> SimpleResponse<T> error(int responseStatus, String message, String moreInfo) {
        // 创建
        SimpleResponse response = new SimpleResponse();
        // TODO
        response.setStatus(responseStatus);
        // TODO
        response.setMessage(message);
        // 返回
        return response;
    }

    /**
     * TODO
    */
    public static <T> SimpleResponse<T> error(int responseStatus, String message) {
        // 返回
        return error(responseStatus, message, null);
    }

    /**
     * TODO
    */
    public static <T> SimpleResponse<T> error(int responseStatus) {
        // 返回
        return error(responseStatus, null, null);
    }
}

